<template>
	<view class="checkin-page">
		<view class="checkin-header">
			<text class="page-title">打卡签到</text>
			<text class="page-subtitle">每日签到，记录成长足迹</text>
		</view>

		<view class="checkin-card">
			<view class="checkin-status">
				<view class="status-icon" :class="{ 'checked': isChecked }">
					<text class="icon-text">{{ isChecked ? '✓' : '○' }}</text>
				</view>
				<text class="status-text">{{ isChecked ? '今日已签到' : '今日未签到' }}</text>
				<text class="checkin-time" v-if="isChecked">{{ checkinTime }}</text>
			</view>

			<view class="checkin-button" @click="handleCheckin" :class="{ 'disabled': isChecked }">
				<text class="button-text">{{ isChecked ? '已签到' : '立即签到' }}</text>
			</view>
		</view>

		<view class="stats-section">
			<view class="stats-title">
				<text class="title-text">签到统计</text>
			</view>
			<view class="stats-grid">
				<view class="stats-item">
					<text class="stats-number">{{ totalDays }}</text>
					<text class="stats-label">总签到天数</text>
				</view>
				<view class="stats-item">
					<text class="stats-number">{{ continuousDays }}</text>
					<text class="stats-label">连续签到</text>
				</view>
				<view class="stats-item">
					<text class="stats-number">{{ thisMonthDays }}</text>
					<text class="stats-label">本月签到</text>
				</view>
			</view>
		</view>

		<view class="calendar-section">
			<view class="calendar-title">
				<text class="title-text">签到日历</text>
			</view>
			<view class="calendar-placeholder">
				<text class="placeholder-text">日历功能开发中...</text>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				isChecked: false,
				checkinTime: '',
				totalDays: 15,
				continuousDays: 5,
				thisMonthDays: 8
			}
		},
		onLoad() {
			this.checkTodayStatus()
		},
		methods: {
			checkTodayStatus() {
				// 模拟检查今日签到状态
				const today = new Date().toDateString()
				const lastCheckin = uni.getStorageSync('lastCheckin')
				this.isChecked = lastCheckin === today
				if (this.isChecked) {
					this.checkinTime = uni.getStorageSync('checkinTime') || '09:30'
				}
			},
			handleCheckin() {
				if (this.isChecked) return
				
				const now = new Date()
				const timeString = now.toTimeString().slice(0, 5)
				const dateString = now.toDateString()
				
				// 保存签到记录
				uni.setStorageSync('lastCheckin', dateString)
				uni.setStorageSync('checkinTime', timeString)
				
				// 更新状态
				this.isChecked = true
				this.checkinTime = timeString
				this.totalDays++
				this.continuousDays++
				this.thisMonthDays++
				
				uni.showToast({
					title: '签到成功！',
					icon: 'success'
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.checkin-page {
		min-height: 100vh;
		background: #f9fafb;
		padding: 40rpx;
	}

	.checkin-header {
		text-align: center;
		margin-bottom: 40rpx;
	}

	.page-title {
		display: block;
		font-size: 48rpx;
		font-weight: bold;
		color: #1f2937;
		margin-bottom: 16rpx;
	}

	.page-subtitle {
		display: block;
		font-size: 28rpx;
		color: #6b7280;
	}

	.checkin-card {
		background: #ffffff;
		border-radius: 24rpx;
		padding: 48rpx 32rpx;
		margin-bottom: 40rpx;
		box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
		text-align: center;
	}

	.checkin-status {
		margin-bottom: 32rpx;
	}

	.status-icon {
		width: 120rpx;
		height: 120rpx;
		border-radius: 50%;
		background: #f3f4f6;
		margin: 0 auto 20rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		transition: all 0.3s ease;
	}

	.status-icon.checked {
		background: linear-gradient(135deg, #10b981, #06b6d4);
	}

	.icon-text {
		font-size: 48rpx;
		color: #6b7280;
		font-weight: bold;
	}

	.status-icon.checked .icon-text {
		color: #ffffff;
	}

	.status-text {
		display: block;
		font-size: 32rpx;
		font-weight: bold;
		color: #1f2937;
		margin-bottom: 8rpx;
	}

	.checkin-time {
		display: block;
		font-size: 24rpx;
		color: #6b7280;
	}

	.checkin-button {
		background: linear-gradient(135deg, #6366f1, #8b5cf6);
		border-radius: 16rpx;
		padding: 24rpx 48rpx;
		transition: all 0.3s ease;
	}

	.checkin-button.disabled {
		background: #e5e7eb;
	}

	.button-text {
		font-size: 32rpx;
		font-weight: bold;
		color: #ffffff;
	}

	.checkin-button.disabled .button-text {
		color: #9ca3af;
	}

	.stats-section {
		margin-bottom: 40rpx;
	}

	.stats-title {
		margin-bottom: 24rpx;
	}

	.title-text {
		font-size: 36rpx;
		font-weight: bold;
		color: #1f2937;
	}

	.stats-grid {
		display: grid;
		grid-template-columns: 1fr 1fr 1fr;
		gap: 20rpx;
	}

	.stats-item {
		background: #ffffff;
		border-radius: 16rpx;
		padding: 32rpx 20rpx;
		text-align: center;
		box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
	}

	.stats-number {
		display: block;
		font-size: 48rpx;
		font-weight: bold;
		color: #6366f1;
		margin-bottom: 8rpx;
	}

	.stats-label {
		display: block;
		font-size: 22rpx;
		color: #6b7280;
	}

	.calendar-section {
		background: #ffffff;
		border-radius: 16rpx;
		padding: 32rpx;
		box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
	}

	.calendar-title {
		margin-bottom: 24rpx;
	}

	.calendar-placeholder {
		height: 400rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		background: #f9fafb;
		border-radius: 12rpx;
	}

	.placeholder-text {
		font-size: 28rpx;
		color: #9ca3af;
	}
</style>

